<?php
namespace app\common\extend\sms;

class Smsbao{
    public $name = '短信宝短信';
    public $ver = '1.0';
    public function submit($phone,$code,$type_flag,$type_des,$text)
    {
        if(empty($phone) || empty($code) || empty($type_flag)){
            return ['code'=>101,'msg'=>'参数错误'];
        }
        $appid = $GLOBALS['config']['sms']['appid'];
        $appkey = $GLOBALS['config']['sms']['appkey'];
        $sign = $GLOBALS['config']['sms']['sign'];
        $tpl = $GLOBALS['config']['sms']['tpl_code_'.$type_flag];
        $params = [
            $code
        ];
        $content = str_replace('${code}',$code,$tpl);
        try {
            $statusStr = array(
                "0" => "短信发送成功",
                "-1" => "参数不全",
                "-2" => "服务器空间不支持,请确认支持curl或者fsocket，联系您的空间商解决或者更换空间！",
                "30" => "密码错误",
                "40" => "账号不存在",
                "41" => "余额不足",
                "42" => "帐户已过期",
                "43" => "IP地址限制",
                "50" => "内容含有敏感词"
            );
            $smsapi = "http://api.smsbao.com/";
            $user = $appid; //短信平台帐号
            $pass = md5($appkey); //短信平台密码
            $content= '【'.$sign.'】'.$content;//要发送的短信内容
            $phone = $phone;//要发送短信的手机号码
            $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
            $result =file_get_contents($sendurl);
            if($result ==0){
                return ['code'=>1,'msg'=>'ok'];
            }
            return ['code'=>101,'msg'=>$statusStr[$result]];
        }
        catch(\Exception $e) {
            return ['code'=>102,'msg'=>'发生异常请重试'];
        }
    }
}